local guyoushiyu = fk.CreateSkill{
    name = "ym2__guyoushiyu",
}
Fk:loadTranslationTable{
    ["ym2__guyoushiyu"] = "固有时域",
    [":ym2__guyoushiyu"] = "连续两张同颜色的牌进入弃牌堆后，你可终止这个回合；若为你的回合，在你的下回合开始前，你视为所有黑色牌的伤害来源。",
    ["@@ym2__guyoushiyu"] = "黑牌的伤害来源",
    ["@[color]ym2__guyoushiyu"] = "固有时域",
    ["#ym2__guyoushiyu-invoke"] = "是否发动 固有时域，结束此回合",
    ["#ym2__guyoushiyu-prompt"] = "是否发动 固有时域，结束此回合，然后直至你下回合开始前，你视为所有黑色牌的伤害来源",

    ["$ym2__guyoushiyu1"] = "カードを切ろう",
    ["$ym2__guyoushiyu2"] = "すまんな、仕上げだ",
}
Fk:addQmlMark{
    name = "color",
    how_to_show = function(_, value)
        if type(value) ~= "table" then return " " end
        return table.concat(table.map(value, function(color)
            if color == Card.Red then
                return "<font color='red'>红</font>"
            else
                return "黑"
            end
        end), " ")
    end,
    qml_path = "",
}
guyoushiyu:addEffect(fk.AfterCardsMove,{
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(guyoushiyu.name) then
            return data.ym2__guyoushiyu and player:getMark("ym2__guyoushiyu-turn") ~= 1
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local prompt = "#ym2__guyoushiyu-invoke"
        local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn)
        if turn_event then
            local to = turn_event.data.who
            if to.id == player.id then
                prompt = "#ym2__guyoushiyu-prompt"
            end
        end
        if room:askToSkillInvoke(player,{
            skill_name = guyoushiyu.name,
            prompt = prompt
        }) then
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn)
        if turn_event then
            local to = turn_event.data.who
            if to.id == player.id then
                room:setPlayerMark(player,"@@ym2__guyoushiyu",1)
            end
        end
        room:setPlayerMark(player,"ym2__guyoushiyu-turn",1)
        room:endTurn()
    end,
})
guyoushiyu:addEffect(fk.AfterCardsMove,{
    can_refresh = function (self, event, target, player, data)
        if player:hasSkill(guyoushiyu.name) then
            for _, move in ipairs(data) do
                if move.toArea == Card.DiscardPile then
                    return true
                end
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local mark = player:getTableMark("@[color]ym2__guyoushiyu")
        local color, trueColor = {}, {}
        for _, move in ipairs(data) do
            if move.toArea == Card.DiscardPile then
                for _, info in ipairs(move.moveInfo) do
                    if Fk:getCardById(info.cardId).color ~= Card.NoColor then
                        table.insert(color,Fk:getCardById(info.cardId).color)
                        table.insertIfNeed(trueColor,Fk:getCardById(info.cardId).color)
                    end
                end
            end
        end
        if #color > #trueColor then
            data.ym2__guyoushiyu = true
        end
        if #mark > 0 then
            for _, value in ipairs(mark) do
                if table.contains(trueColor,value) then
                    data.ym2__guyoushiyu = true
                    break
                end
            end
        end
        room:setPlayerMark(player,"@[color]ym2__guyoushiyu",trueColor)
    end,
})
guyoushiyu:addEffect(fk.TurnStart,{
    can_refresh = function (self, event, target, player, data)
        return target == player and player:getMark("@@ym2__guyoushiyu") ~= 0
    end,
    on_refresh = function (self, event, target, player, data)
        player.room:setPlayerMark(player,"@@ym2__guyoushiyu",0)
    end,
})
guyoushiyu:addEffect(fk.PreDamage,{
    can_refresh = function (self, event, target, player, data)
        return data.card and data.card.color == Card.Black and player:getMark("@@ym2__guyoushiyu") ~= 0
    end,
    on_refresh = function (self, event, target, player, data)
        data.from = player
    end,
})
guyoushiyu:addLoseEffect(function (self, player, is_death)
    player.room:setPlayerMark(player,"@[color]ym2__guyoushiyu",0)
end)
return guyoushiyu